﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///BBS 的摘要说明
/// </summary>
public partial class BBS
{
    DataTableDataContext db = new DataTableDataContext();

    //返回所有公告信息
    public IEnumerable<BBS> returnbbs()
    {
        var bbs = from b in db.BBS select b;
        return bbs;
    }

    //返回最后五条公告
    public IEnumerable<BBS> returnLastFiveBBS()
    {
        var bbs =(from b in db.BBS orderby b.bbsId descending select b).Take(5).ToList();
        return bbs;
    }

    //根据bbsId查找BBS内容
    public IEnumerable<BBS> GetBBSById(int id)
    {
        var BBSContent= from b in db.BBS where b.bbsId==id select b;

        return BBSContent; 
    }
    
    //增加BBS
    public void InsertBBS( string NewTitle, string NewContent,
                          DateTime NewInTime)
    {
        BBS  bbs = new BBS
        {
           
            title = NewTitle,
            content = NewContent,
            INTime= NewInTime,
           
        };
        db.BBS.InsertOnSubmit(bbs);
        db.SubmitChanges();

    }

    //删除BBS
    public void DeleteBBS(int id)
    {
        var bbss = from b in db.BBS where b.bbsId == id select b;
        foreach (var bbs in bbss)
        {
            db.BBS.DeleteOnSubmit(bbs);
            db.SubmitChanges();
        }

    }


}